package JasonsClasses;
import java.util.*;

public class AI {
	//function does the same thing as placeboats function, but it replaces the user input with random numbers	
	public void randomlyplaceboats(GameBoard board){
		int width, height, i, j, x, y;
		width = board.getWidth();
		height = board.getHeight();
		int[] boatLengths = {2, 3, 3, 4, 5};
		Random generator = new Random(System.nanoTime());
		boolean orientation, placeOkay = true;
		
		//clear the board incase a previous game has taken place
		for(i=0;i<width;i++){
			for(j=0;j<height;j++){
				if(board.isEmpty(i, j)){
					board.clearSpace(i, j);
				}
			}
		}
		//place each boat in boatLengths
		//orientation key (true = vertical, false = horizontal)
		i=0;
		do{
			orientation = generator.nextBoolean();
			if(orientation){
				y = generator.nextInt(height - boatLengths[i]);
				x = generator.nextInt(width);
				for(j=0;j<boatLengths[i];j++){
					if(!(board.isEmpty(x, y+j))){
						placeOkay = false;
						break;
					}
				}
				if(placeOkay == true){
					i++;
				}
			}
			else{
				x = generator.nextInt(width - boatLengths[i]);
				y = generator.nextInt(height);
				for(j=0;j<boatLengths[i];j++){
					if(!board.isEmpty(x, y+j)){
						placeOkay = false;
						break;
					}
				}
				if(placeOkay == true){
					i++;
				}
			}
		}while(i<boatLengths.length);
		
	}
	
	
}
